<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/6
 * Time: 20:55
 */


require_once "dataSQL.php";
require_once "rootDB.php";
$rootDB=new rootDB();
$user=$_POST['user'];
$password=$_POST['pass'];
$code=$_POST['code'];
$addtime=time();
$password=md5($password);
$datea=$rootDB->selectAdmin($user);

if($datea==null) {
    session_start();
    $_SESSION['user']=$user;
    $data = $rootDB->add_admin($user, $password,$code, $addtime);
    try {
        $result = $data;
        if ($result) {
            $dat = array(
                'message' =>"注册成功",
            );
            echo json_encode($dat);
        } else {
            $dat = array(

                'message' =>"注册失败",

            );
            echo json_encode($dat);

        }
    }
    catch (Exception $e) {

        // 回滚事务
        // $pdo->rollback();
        echo $e->getMessage();}

}
else
{

    $dat = array(

        'message' =>"该账号以及存在，请登陆",
       'data'=>$datea,

    );
    echo json_encode($dat);


}

